package Demo3;

import Demo2.Booklist;

import java.util.Scanner;

public class Return implements IFuntion{
    @Override
    public void work(Booklist booklist) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入需要归还的书籍名称:>");
        String bookName = scanner.nextLine();
        //遍历数组
        int sz = booklist.getCount();
        int i = 0;
        for (; i < sz; i++) {
            if (booklist.getBook(i).getName().equals(bookName)) {
                break;//找到了
            }
        }
        //找不到
        if(sz == i) System.out.println("输入的归还书籍不存在");
        //找到了，将书籍状态设置为未借出后提示归还
        else {
            booklist.getBook(i).borrowed = false;
            System.out.println("书籍归还成功！");
        }
    }
}
